using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Linq;
namespace MicroMsg.Common.Utils
{
	public class VersionHelper
	{
		private const string TAG = "VersionHelper";
		private const string CHANNELID = "ChannelID";
		private static Dictionary<string, string> mapProperties;
		private static uint mProtocolVersion;
		public static string Version
		{
			get
			{
				return VersionHelper.getValueByKey("Version");
			}
		}
		public static string ProductId
		{
			get
			{
				return VersionHelper.getValueByKey("ProductID");
			}
		}
		public static string Genre
		{
			get
			{
				return VersionHelper.getValueByKey("Genre");
			}
		}
		public static string Description
		{
			get
			{
				return VersionHelper.getValueByKey("Description");
			}
		}
		public static string Publisher
		{
			get
			{
				return VersionHelper.getValueByKey("Publisher");
			}
		}
		public static int ChannelId
		{
			get
			{
				int result;
				try
				{
					int num = VersionHelper.Description.IndexOf("ChannelID");
					if (num < 0)
					{
						result = 0;
					}
					else
					{
						string text = VersionHelper.Description.Substring(num + "ChannelID".get_Length());
						if (string.IsNullOrEmpty(text))
						{
							result = 0;
						}
						else
						{
							int num2 = int.Parse(text);
							result = num2;
						}
					}
				}
				catch (Exception)
				{
					result = 0;
				}
				return result;
			}
		}
		private static void checkMap()
		{
			if (VersionHelper.mapProperties != null)
			{
				return;
			}
			VersionHelper.mapProperties = new Dictionary<string, string>();
			try
			{
				XDocument xDocument = XDocument.Load("WMAppManifest.xml");
				using (XmlReader xmlReader = xDocument.CreateReader(0))
				{
					xmlReader.ReadToDescendant("App");
					if (xmlReader.IsStartElement())
					{
						xmlReader.MoveToFirstAttribute();
						while (xmlReader.MoveToNextAttribute())
						{
							VersionHelper.mapProperties.Add(xmlReader.get_Name(), xmlReader.get_Value());
						}
					}
				}
			}
			catch (Exception)
			{
			}
		}
		public static string getValueByKey(string string_0)
		{
			VersionHelper.checkMap();
			if (VersionHelper.mapProperties.ContainsKey(string_0))
			{
				return VersionHelper.mapProperties.get_Item(string_0);
			}
			return "";
		}
		public static uint getProtocolVersion()
		{
			if (VersionHelper.mProtocolVersion != 0u)
			{
				return VersionHelper.mProtocolVersion;
			}
			string version = VersionHelper.Version;
			string[] array = version.Split(new char[]
			{
				'.'
			});
			uint num = 1610612736u;
			uint num2 = 3u;
			uint num3 = 1u;
			uint num4 = 1u;
			uint num5 = 1u;
			if (array.Length >= 4)
			{
				try
				{
					num2 = uint.Parse(array[0]);
					num3 = uint.Parse(array[1]);
					num4 = uint.Parse(array[2]);
					num5 = uint.Parse(array[3]);
				}
				catch (Exception)
				{
				}
			}
			num |= (num2 & 255u) << 24;
			num |= (num3 & 255u) << 16;
			num |= (num4 & 255u) << 8;
			num |= (num5 & 255u);
			VersionHelper.mProtocolVersion = num;
			return num;
		}
	}
}
